<?php

namespace addons\qingdongams\model;

use think\Exception;
use think\Model;
use traits\model\SoftDelete;

/**
 * 售后问题分类管理
 */
class AftermarketType Extends Model {
	use SoftDelete;

    // 表名,不含前缀
    protected $name = 'qingdongams_aftermarket_type';
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = 'int';
	// 定义时间戳字段名
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	protected $deleteTime = 'deletetime';


	//创建产品
	public static function createType($params) {
		$staff = Staff::info();
		if (!empty($staff)) {
			$params['create_staff_id'] = $staff->id;
		}
		$customer = new self;
		// 调用当前模型对应的User验证器类进行数据验证
		$result = $customer->allowField(true)->save($params);
		$lastId = $customer->getLastInsID();
		if (false === $result) {
			// 验证失败 输出错误信息
			throw new Exception($customer->getError());
		}
		return $lastId;
	}


	/**
	 *修改产品
	 */
	public static function updateType($params) {

		$customer = new self;
		// 调用当前模型对应的User验证器类进行数据验证
		$result = $customer->save($params, ['id' => $params['id']]);
		if (false === $result) {
			// 验证失败 输出错误信息
			throw new Exception($customer->getError());
		}
		return true;
	}
}
